import json
import re


def remove_json_comments(json_str):
    # pattern = r'("(?:[^//"]|\\.)*")|//.*$|\/\*[\s\S]*?\*\/'
    pattern = r'("(?:[^\\"]|\\.)*")|(/\*.*?\*/)'
    # pattern = r'(?<!http:)//.*|/\*(.|\n)*?\*/'
    json_str = re.sub(pattern, lambda m: m.group(0) if m.group(1) else '', json_str)

    return json_str


def remove_json_comments2(json_str):
    # 去除单行注释
    json_str = re.sub(r'//.*', '', json_str)
    # 去除多行注释
    json_str = re.sub(r'/\*.*?\*/', '', json_str)
    # 解析JSON字符串为Python对象,再
    data = json.dumps(json.loads(json_str))
    return data


# 测试代码
json_string = '''
{
// name sdasdas
   "name": "John{{de/* another comment */}}", // This is a comment "name": "John",
   "age": /* another comment */ 30,
   "city": "New York" /* another comment */
}
'''

cleaned_json = remove_json_comments2(json_string)
print(cleaned_json)

